import * as homeApi from '@/common/apis/home-api.js';
import user from '@/store/modules/user.js';

export default {
    namespaced: true,
    state: {
        homeData: [],
        MmvBuyBasicList: [],// 车辆购买列表的数据
        advertList: [], // 轮播列表
		showDragCoupon:false,
    },
    mutations: {
        setHomeData(state, homeData) {
            state.homeData = homeData;
        },
        setMmvBuyBasicList(state, list) {
            state.MmvBuyBasicList = list;
        },
        setAdvertList(state, list) {
            state.advertList = list;
        },
        setShowDragCoupon(state, flag) {
            state.showDragCoupon = flag;
        },
    },
    actions: {
        getHomeData({ commit }, params) {
            const homeData = [
                {
                    components: 'MmvNotice',
                },
                {
                    components: 'MmvMenu',
                },
            ];

            if (params == '首页') {
                // homeData.push({
                //     components: 'MmvCoupon',
                // });
                homeData.push({
                    components: 'MmvHotInformation',
                });
                homeData.push({
                    components: 'MmvPopularActivities',
                });
            }
            if (params == '车辆租赁') {
                homeData.push({
                    components: 'MmvPopularCarRental',
                });
            }
            if (params == '车辆购买') {
                homeData.push({
                    components: 'MmvBuyBasicList',
                });
            }
            if (params == '车主服务') {
                homeData.push({
                    components: 'MmvPopularActivities',
                });
            }
            commit('setHomeData', homeData);
        },

        /**
         * 获取车辆购买列表数据
         */
        async getMmvBuyBasicList({ commit }, params) {
            const deptId = this.state.app.storeInfo.storeId; // 门店ID
            const result = await homeApi.scheme({
                ...params,
                deptId,
                bizType: 5, // 5 直购
                schemeType: 1,
            });
            commit('setMmvBuyBasicList', result);
        },
		
		/**
		 * 记录分享
		 */
		async recordShare({commit}, params={}){
			
			params.openid = user.state.openid;
			params.tenantId = user.state.tenantId;
			params.objType = getApp().globalData.objType;
			params.objId = getApp().globalData.objId;
			await homeApi.recordCustomerShare(params);
		},
		
		/**
		 * 记录使用
		 */
		async recordUse({commit}, params={}){
			
			params.customerOpenid = user.state.openid;
			params.tenantId = user.state.tenantId;
			params.deptId = user.state.deptId;
			params.customerPhone = user.state.userInfo.phone;
			params.customerNickName = user.state.userInfo.nickName;
			params.customerAvatar = user.state.userInfo.portraitImg;
			
			params.objType = getApp().globalData.objType;
			params.objId = getApp().globalData.objId;
			params.taskObjId = getApp().globalData.taskObjId;
			params.personnelType = getApp().globalData.personnelType;
			params.personnelId = getApp().globalData.personnelId;
			await homeApi.recordCustomerOperate(params);
		}
		
    },
}